package tk.mybatis.springboot.test;

import org.openjdk.jol.info.ClassLayout;
import org.openjdk.jol.info.GraphLayout;
import tk.mybatis.springboot.model.UserInfo;

import java.util.*;

public class JolDemo {

    static Object generate() {
        Map<String, Object> map = new HashMap<>();
        map.put("a", new Integer(1));
        map.put("b", "b");
        map.put("c", new Date());

        for (int i = 0; i < 10; i++) {
            map.put(String.valueOf(i), String.valueOf(i));
        }
        return map;
    }

    static Object users() {
        List<UserInfo> array = new ArrayList<>(10000);
        for (int i = 0; i < 1; i++) {
            UserInfo userInfo = new UserInfo();
            userInfo.setUsername("test" + i);
            userInfo.setPassword("pas" + i);
            userInfo.setEmail("email" + i);
            userInfo.setUsertype("0");
            userInfo.setEnabled(i);
            userInfo.setQq("qq" + i);
            userInfo.setTel("tel" + i);
            array.add(userInfo);
        }
        return array;
    }

    static void print(String message) {
        System.out.println(message);
        System.out.println("=============================================================================================================================================================================================");
    }

    public static void main(String[] args) {
//        Object obj = generate();
        Object obj = users();

        //查看对象内部信息
        print(ClassLayout.parseInstance(obj).toPrintable());

        //查看对象外部信息
        print(GraphLayout.parseInstance(obj).toPrintable());

        //获取对象总大小
        print("size : " + GraphLayout.parseInstance(obj).totalSize());
    }
}